<template>
  <view class="container">
    <view class="goods_list" v-if="result.length>0">
      <view class="goods_unit" v-for="(item,index) in result" :key="index" :id="item.healthy_id" v-on:click="goods_detail">
        <image class="goods_unit_pic" :style="{height:pic_h}" mode="aspectFill" :src="www+item.img_url"></image>
        <view class="goods_name" v-if="item.healthy_title.length > 12">{{item.healthy_title.substr(0,12)}}…</view>
        <view class="goods_name" v-else>{{item.healthy_title}}</view>
        <view class="goods_property">
          <view class="goods_price" v-if="item.desc.length > 20">{{item.desc.substr(0,20)}}…</view>
          <view class="goods_price" v-else>{{item.desc}}</view>
        </view>
        <view class="foot"></view>
      </view>
    </view>
    <view class="e" v-else>暂无信息</view>
  </view>
</template>
<style>
page{background: #F5F5F5;}
.navigation image{width:35upx;height: 35upx;}
.navigation view{font-size: 32upx;color: #333;text-align: center;margin-left:33%;}
.goods_list{width:94%;margin:10upx 3%;display: flex;justify-content: space-between;align-items: center;flex-wrap: wrap;}
.goods_unit{width:100%;background: #FFFFFF;/* box-shadow: 0px 0px 6px #ccc; */margin:20upx 0;display: flex;border-radius: 10upx;overflow: hidden;
  flex-direction: column;justify-content: space-between;align-items: flex-start;padding-bottom: 10upx;background: #FFFFFF;}
.goods_unit_pic{
  width: 94%;
  overflow: hidden;
  margin-left: 3%;
  margin-top: 2%;
}
.goods_name{width:100%;padding:0 2%;line-height: 40upx;font-size: 17px;color: #282828;margin-top:15px;}
.goods_property{width:100%;padding:0 2%;display: flex;justify-content: space-between;align-items: center;height: 40upx;}
.goods_price{color: #7d7a7a;margin-top:15px;font-size: 12px}
.goods_property image{width:50upx;height: 50upx;}
.e {
  text-align: center;
  top: 0;
  color: #8a8888;
  font-size: 24px;
}
.foot {
  margin-top: 15px;
}

</style>
<script>
export default{
  data(){
    return {
      pic_h:'',
      nav_h:'',
      nav_lh:'',
      result:[],
      sort:0,
      status:0,
      start:0,
      url: getApp().globalData.url,
      www: 'https://www.jdmuguzhid.com',
      static:getApp().globalData.static
    }
  },
  onLoad(e) {
    var res = uni.getSystemInfoSync();
    this.nav_h  = res.statusBarHeight +35+ "px";
    this.nav_lh = res.statusBarHeight +45+ "px";
    this.pic_h = res.windowWidth/3+"px";
    this.sort   = parseInt(e.sort);
    const scene = decodeURIComponent(e.scene);
    var upid = uni.getStorageSync("upid");
    if(scene=="undefined"||scene==undefined)
    {
      if(upid=="" || upid==undefined || upid=="undefined")
      {
        if(e.upid==undefined)
        {
          uni.setStorageSync("upid",0);
        }
        else
        {
          uni.setStorageSync("upid",parseInt(e.upid));
        }
      }
    }
    else
    {
      uni.setStorageSync("upid",scene);
    }
  },
  onShow(){
    this.initialize();
  },
  onReachBottom:function()
  {
    this.status = 1;
    this.initialize();
  },
  methods:{
    reback:function()
    {
      uni.navigateBack();
    },
    goods_detail:function(e)
    {
      var id = e.currentTarget.id;
      uni.navigateTo({
        url:"./healthy_detail?id="+id
      })
    },
    initialize:function()
    {
      var that = this;
      var member_id = uni.getStorageSync("member_id");
      //#ifdef MP-WEIXIN
      var type = "weixin";
      //#endif
      //#ifdef APP-PLUS
      var type = "app";
      //#endif
      //#ifdef H5
      var type = "app";
      //#endif
      uni.request({
        url: that.url+'/wechat_healthy',
        data: {sort:this.sort,type:type,member_id:member_id,start:this.start},
        header: {'Content-Type': 'application/json'},
        success: (res) => {
          if(res.data.status==1)
          {
            that.start += 10;
            for(var i=0;i<res.data.result.length;i++)
            {
              that.result.push(res.data.result[i]);
            }
          }
        }
      })
    }
  }
}
</script>
